<script setup>
//导入pinia中的user数据
import router from "@/router/router.js";
import { defineUser } from "../stores/userStore.js";
import { defineSchedule } from "../stores/scheduleStore.js";

let sysUser = defineUser();
let schedule = defineSchedule();
//退出登录，清除pinia数据
function logout() {
  sysUser.$reset();
  schedule.$reset();
  //回到登录界面
  router.push("/login");
}
</script>

<template>
  <div>
    <h1 class="ht">欢迎使用日程管理系统</h1>
    <div class="operate">
      <div class="optionDiv" v-if="sysUser.username==''">
        <router-link to="/login">
          <button class="button button-small">登录</button>
        </router-link>
        <router-link to="/regist">
          <button class="button button-small">注册</button>
        </router-link>
      </div>

      <div class="optionDiv" v-if="sysUser.username!=''">
        欢迎{{ sysUser.username }}
        <button class="button button-small" @click="logout()">退出登录</button>
        <router-link to="/showSchedule">
          <button class="button button-large">查看我的日程</button>
        </router-link>
      </div>
    </div>
  </div>
</template>


<style scoped>
  .ht {
    text-align: center;
    color: cadetblue;
    font-family: 幼圆;
  }

  .button {
    border: 2px solid powderblue;
    border-radius: 4px;
    background-color: antiquewhite;
    height: 28px;
    margin-right: 10px;
  }

  .button-small {
    width: 80px; /* Adjust according to your preference */
  }

  .button-large {
    width: 120px; /* Adjust according to your preference */
  }

  .operate {
    height: 40px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }

  .optionDiv {
    margin-right: 20px; /* Adjust margin for better spacing */
  }
</style>

